textStorage.removeAttribute(
.backgroundColor, range: NSRange(location: 0, length: textStorage.length))
- for range in highlightRanges {
+ for (index, range) in highlightRanges.enumerated() {
let nsRange = NSRange(range, in: textStorage.string)
- textStorage.addAttribute(.backgroundColor, value: NSColor.Syntax.match, range: nsRange)
+ let color = index == selectedRange ? NSColor.Syntax.highlightMatch : NSColor.Syntax.match
+ textStorage.addAttribute(.backgroundColor, value: color, range: nsRange)
}
textView.needsDisplay = true
let range = highlightRanges[selectedRange]
let nsRange = NSRange(range, in: textStorage.string)
textView.scrollRangeToVisible(nsRange)
- textView.selectedRange = nsRange
}
}
}
}
-
- private func setSelectionColor() {
- guard let textView = self.textView else { return }
-
- var selectedTextAttributes = textView.selectedTextAttributes
- selectedTextAttributes[.backgroundColor] = NSColor.yellow.withAlphaComponent(0.3)
- textView.selectedTextAttributes = selectedTextAttributes
- }
}
extension MapTextEditorController: NSTextViewDelegate {
context: NSViewControllerRepresentableContext<MapTextEditor>
) {
nsViewController.highlightRanges = highlightRanges
- nsViewController.selectedRange = selectedRange
+ if nsViewController.selectedRange != selectedRange {
+ nsViewController.selectedRange = selectedRange
+ }
}
}